package com.jiuli_travel.common;

import com.jiuli_travel.utils.AliOSSUtils;
import com.jiuli_travel.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
/**
 *   文件上传到阿里云通用接口
 */
@RestController
@RequestMapping("/api")
@Slf4j
@CrossOrigin
public class FileUpload {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/file-upload")
    public Result fileUpload(MultipartFile file){

        log.info("文件上传");

        String upload = null;
        try {
            upload = aliOSSUtils.upload(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return Result.ok(upload);

    }
}
